package com.logic.landseaserver.ws.dto;

import com.logic.common.exception.BusinessException;
import com.logic.landseaserver.domain.Customer;
import com.logic.system.domain.User;

public class UserDTO {

    private Integer id;

    private String loginId;

    private String password;

    private Boolean updatePwdFlag;

    private CustomerDTO customerDTO;

    public String getLoginId() {
        return loginId;
    }

    public void setLoginId(String loginId) {
        this.loginId = loginId;
    }

    public CustomerDTO getCustomerDTO() {
        return customerDTO;
    }

    public Boolean getUpdatePwdFlag() {
        return updatePwdFlag;
    }

    public void setUpdatePwdFlag(Boolean updatePwdFlag) {
        this.updatePwdFlag = updatePwdFlag;
    }

    public void setCustomerDTO(CustomerDTO customerDTO) {
        this.customerDTO = customerDTO;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }


    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public static User fromDTOtoUser(UserDTO userDTO) throws BusinessException {
        User user = new User();
        user.setId(userDTO.getId());
        user.setLoginId(userDTO.getLoginId());
        user.setUpdatePwdFlag(userDTO.getUpdatePwdFlag());
        user.setPassword(userDTO.getPassword());
        Customer customerDTO = new Customer();
        customerDTO.setCertificatesAddress(userDTO.getCustomerDTO().getCertificatesAddress());
        customerDTO.setCertificatesNo(userDTO.getCustomerDTO().getCertificatesNo());
        customerDTO.setCertificatesType(userDTO.getCustomerDTO().getCertificatesType());
        customerDTO.setName(userDTO.getCustomerDTO().getName());
        customerDTO.setGender(userDTO.getCustomerDTO().getGender());
        customerDTO.setPhone(userDTO.getCustomerDTO().getPhone());
        customerDTO.setUserId(userDTO.getId());
        
        //tony添加字段
        if(userDTO.getCustomerDTO().getBirthday()!=null)
        customerDTO.setBirthday(userDTO.getCustomerDTO().getBirthday());
        if(userDTO.getCustomerDTO().getGender()!=null)
        customerDTO.setGender(userDTO.getCustomerDTO().getGender());
        if(userDTO.getCustomerDTO().getHobby()!=null)
        customerDTO.setHobby(userDTO.getCustomerDTO().getHobby());
        if(userDTO.getCustomerDTO().getImgUrl()!=null)
        customerDTO.setImgUrl(userDTO.getCustomerDTO().getImgUrl());
        if(userDTO.getCustomerDTO().getOpenId()!=null)
        customerDTO.setOpenId(userDTO.getCustomerDTO().getOpenId());
        if(userDTO.getCustomerDTO().getJob()!=null)
        customerDTO.setJob(userDTO.getCustomerDTO().getJob());
        if(userDTO.getCustomerDTO().getNickName()!=null)
        customerDTO.setNickName(userDTO.getCustomerDTO().getNickName());
        if(userDTO.getCustomerDTO().getUniId()!=null)
        customerDTO.setUniId(userDTO.getCustomerDTO().getUniId());
        
        user.setCustomer(customerDTO);
        return user;
    }
}
